package com.platform.config;

import org.redisson.Redisson;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;

@Configuration
public class RedisConfig {

    @Value("${spring.redis.host}")
    private String host;
//    private final String host = "localhost";

    @Value("${spring.redis.password}")
    private String passwd;// = "eiFaequ0ahgh7Chiexaehong3eigoh4teesha3Kee9vee6aa3sah6Hax4iethe1aenae3uengai9pagheiboo2ka9ohqu3Biexam7ocoh1Yoolohnaehaesh1Eepali1chai7thooph1ochie8Yah4xahp7laigh6chaisieph4waNgah7Noe2yaaxoo4oMahy3too8FeiFaequ0ahgh7Chiexaehong3eigoh4teesha3Kee9vee6aa3sah6Hax4iethe1aenae3uengai9pagheiboo2ka9ohqu3Biexam7ocoh1Yoolohnaehaesh1Eepali1chai7thooph1ochie8Yah4xahp7laigh6chaisieph4waNgah7Noe2yaaxoo4oMahy3too8F";

    @Bean(name = {"redisTemplate", "stringRedisTemplate"})
    public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory factory) {
        StringRedisTemplate redisTemplate = new StringRedisTemplate();
        redisTemplate.setConnectionFactory(factory);
        return redisTemplate;
    }
 
    @Bean
    // 定义一个redisson客户端
    public Redisson redisson() {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://"+host+":6379");//.setPassword(passwd);
//        config.useSingleServer().setAddress("redis://117.72.40.8:20029").setPassword(passwd);
        return (Redisson) Redisson.create(config);
    }
 
}
